var e, a = require("../../utils/util.js"), t = getApp();

t.globalData.url;

Page({
    data: {
        remind: "加载中",
        angle: 0,
        userInfo: {},
        state: 0,
        ishidden: !1,
        ishidden1: !1
    },
    goToIndex: function() {
        var e = this, a = e.data.shareShopId, t = e.data.autoId;
        "" != e.data.shareShopId && "" == e.data.autoId ? wx.redirectTo({
            url: "/pages/home/detail/detail?id=" + a
        }) : "" != e.data.autoId && "" == e.data.shareShopId ? wx.redirectTo({
            url: "/pages/autoWash/prepares1/index?id=" + t
        }) : "" != e.data.shareCustId && "" == e.data.autoId && "" == e.data.shareShopId ? wx.redirectTo({
            url: "/pages/info/share/index?custId=" + e.data.shareCustId
        }) : "" == e.data.shareCustId && "" == e.data.autoId && "" == e.data.shareShopId && "" != e.data.serviceOrderId ? wx.redirectTo({
            url: "/pages/autoWash/share/index?serviceOrderId=" + e.data.serviceOrderId
        }) : (wx.switchTab({
            url: "/pages/home/home"
        }), wx.removeStorageSync("autoId"), wx.removeStorageSync("shareShopId"), wx.removeStorageSync("serviceOrderId"));
    },
    onLoad: function(a) {
        e = this;
        var t = wx.getStorageSync("shareShopId");
        e.setData({
            shareShopId: t
        });
        var r = wx.getStorageSync("autoId");
        e.setData({
            autoId: r
        });
        var d = wx.getStorageSync("shareCustId");
        e.setData({
            shareCustId: d
        });
        var s = wx.getStorageSync("serviceOrderId");
        e.setData({
            serviceOrderId: s
        }), wx.getLocation({
            success: function(e) {
                wx.setStorageSync("latitude", e.latitude), wx.setStorageSync("longitude", e.longitude);
            }
        });
        var o = wx.getStorageSync("avatarUrl");
        o ? (e.setData({
            avatarUrl: o
        }), e.setData({
            ishidden: !0
        })) : e.setData({
            ishidden: !1
        }), wx.getStorageSync("ivs") ? e.setData({
            ishidden1: !0
        }) : e.setData({
            ishidden1: !1
        });
    },
    onShow: function() {
        var a = wx.getStorageSync("shareShopId");
        e.setData({
            shareShopId: a
        }), this.getUserIsRegister();
    },
    bindGetUserInfo: function(e) {
        var r = this, d = (r.data.state, r.data.shareShopId), s = r.data.autoId;
        e.detail.userInfo ? (r.setData({
            avatarUrl: e.detail.userInfo.avatarUrl,
            iv: e.detail.iv,
            encryptedData: e.detail.encryptedData
        }), a.registerUser(r.data.encryptedData, r.data.iv, t, function(e) {
            console.log(e)
            // wx.switchTab({
        //         url: "/pages/home/home"
        //     });
        }), wx.showToast({
            title: "授权成功",
            icon: "success"
        })) : wx.showToast({
            title: "请授权",
            icon: "none"
        });
    },
    onReady: function() {
        var e = this;
        setTimeout(function() {
            e.setData({
                remind: ""
            });
        }, 1e3), wx.onAccelerometerChange(function(a) {
            var t = -(30 * a.x).toFixed(1);
            t > 14 ? t = 14 : t < -14 && (t = -14), e.data.angle !== t && e.setData({
                angle: t
            });
        }), setTimeout(function() {
            wx.showToast({
                title: "登陆前记得授权哦",
                icon: "none"
            });
        }, 1e3);
    },
    getUserIsRegister: function() {
        wx.login({
            success: function(e) {
                a.request(t, "user/NomalUser/NomalUserhasRegister", "POST", {
                    code: e.code
                }, function(e) {
                    e.state && (null != e.data ? wx.setStorageSync("UserRegister", !0) : wx.setStorageSync("UserRegister", !1));
                }, function(e) {});
            }
        });
    },
    onUnload: function() {
        wx.removeStorageSync("shareShopId"), wx.removeStorageSync("autoId");
    }
});